package com.hymall.controller.admin;

import com.hymall.bean.MarketIssue;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.service.admin.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author: 牟治宇
 * @description 商场管理-->通用问题
 * @date: 2022/7/18 10:57
 */


@RestController
@RequestMapping("/admin/issue")
public class AdminIssueController {

    @Autowired
    IssueService issueService;

    // @GetMapping("list")
    // public BaseRespVo issueList(BasePageInfo basePageInfo){
    //
    // }

    /**
     * @author 牟治宇
     * @description 商场管理--通用问题列表
     * @date 2022/7/18 19:37
     * @param [basePageInfo, question]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @GetMapping("list")
    public BaseRespVo issueList(BasePageInfo basePageInfo,String question){

        CommonData data = issueService.issueList(basePageInfo,question);
        return BaseRespVo.ok(data);
    }


    /**
     * @author 牟治宇
     * @description 商场管理--通用问题列表--添加问题和回答
     * @date 2022/7/18 19:38
     * @param [map]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @PostMapping("create")
    public BaseRespVo issueCreate(@RequestBody Map<String,Object> map){
        String question = (String) map.get("question");
        String answer = (String) map.get("answer");
        MarketIssue marketIssue = issueService.insertIssue(question,answer);
        return BaseRespVo.ok(marketIssue);
    }

    /**
     * @author 牟治宇
     * @description 商场管理--通用问题列表--更新问题列表
     * @date 2022/7/18 19:38
     * @param [marketIssue]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @PostMapping("update")
    public BaseRespVo issueUpdate(@RequestBody MarketIssue marketIssue){
        int code  = issueService.updateIssue(marketIssue);
        if (code != 1){
            return BaseRespVo.error(1,"error");
        }
        return BaseRespVo.ok();
    }


    /**
     * @author 牟治宇
     * @description 商场管理--通用问题列表--问题删除
     * @date 2022/7/18 19:39
     * @param [marketIssue]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @PostMapping("delete")
    public BaseRespVo issueDelete(@RequestBody MarketIssue marketIssue){

        int code = issueService.deleteIssue(marketIssue);
        if (code != 1){
            return BaseRespVo.error(1,"error");
        }
        return BaseRespVo.ok();
    }
}
